home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / translate / anlparm.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  1KB  |  47 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include "../misc/misc.h"
  5.  
  6. /*
  7.     Read argument from a file.
  8.     This function is used for DOS (Ya, this kit is used on DOS, not linuxconf)
  9.     to go around the command line length limitation.
  10.  
  11.     Return the number of argument placed in newargv[].
  12.  
  13.     It reads the argument and whenever one start with a @, it assumes
  14.     the argument is a file containing arguments.
  15. */
  16. int anlparm (int argc, char *argv[], char *newargv[])
  17. {
  18.     int ret = 0;
  19.     for (int i=0; i<argc; i++){
  20.         if (argv[i][0] == '@'){
  21.             FILE *fin = fopen (argv[i]+1,"r");
  22.             if (fin == NULL){
  23.                 fprintf (stderr,"Ne peut ouvrir %s (%s)\n"
  24.                     ,argv[i]+1,strerror(errno));
  25.             }else{
  26.                 char buf[300];
  27.                 while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
  28.                     char *pt = buf;
  29.                     while (1){
  30.                         pt = str_skip (pt);
  31.                         if (*pt == '\0') break;
  32.                         char word[300];
  33.                         pt = str_copyword (word,pt);
  34.                         newargv[ret++] = strdup (word);
  35.                     }
  36.                 }
  37.                 fclose (fin);
  38.             }
  39.         }else{
  40.             newargv[ret++] = argv[i];
  41.         }
  42.     }
  43.     newargv[ret] = NULL;
  44.     return ret;
  45. }
  46.  
  47.